package org.zuel.Luce.controller;

import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.search.highlight.InvalidTokenOffsetsException;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.zuel.Luce.service.ILuceService;

import java.io.IOException;

@RestController
@RequestMapping(value = "/luce")
public class LuceController {
    @Autowired
    private ILuceService iLuceService;
    LuceController( ILuceService iLuceService){
        this.iLuceService=iLuceService;
    }
    @PostMapping(value = "/create")
    public Object create() throws IOException {
        return iLuceService.createIndex();
    }

    @CrossOrigin
    @Transactional
    @GetMapping(value = "/seach/{text}")
    public Object seach(@PathVariable String text) throws InvalidTokenOffsetsException, IOException, ParseException {
        return iLuceService.search(text);
    }

}
